package org.jspresso.framework.application.frontend.action.std;

import java.util.Collection;
import java.util.Map;

import org.jspresso.framework.action.IActionHandler;
import org.jspresso.model.ActionTestIo;
import org.jspresso.model.TestEntity;

public class SetConnectorValueAndFireChangeEventAction<E,F,G> extends SetConnectorValueAction<E,F,G> {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public boolean execute(IActionHandler actionHandler, Map context) {
		if(getModel(context) instanceof Collection) { // List situation, we don't want to use the super.execute(). We'll fire a property change event for the TestEntity displayable name as it may have changed during target component edition
			((TestEntity)getSelectedModel(context)).firePropertyChange(TestEntity.DISPLAYABLE, TestEntity.UNKNOWN, ((TestEntity)getSelectedModel(context)).getDisplayable());
			return true;
		}
		else {
			((ActionTestIo)getParentModel(context)).firePropertyChange(ActionTestIo.PARAMETER_REF_VALUE, ActionTestIo.UNKNOWN, getModel(context));
			return super.execute(actionHandler, context);

		}
	}

}
